#include "logdialog.h"
#include "ui_logdialog.h"

LogDialog::LogDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::LogDialog)
{
    ui->setupUi(this);

    setLogLevelColor(0,"#000000");
    setLogLevelColor(1,"#000000");
    setLogLevelColor(2,"#0000ff");
    setLogLevelColor(3,"#ff6600");
    setLogLevelColor(4,"#ff3300");
    setLogLevelColor(5,"#ff0000");
    setLogLevelColor(6,"#ff0000");
}

LogDialog::~LogDialog()
{
    delete ui;
}

void LogDialog::setLogLevelColor(int level, const QString & colorHex)
{
    logColorMap[level] = colorFrontA+colorHex+colorFrontB;
}

void LogDialog::update(int level, const char * msg)
{
    auto log = logColorMap[level]+ msg +colorFrontEnd;
    ui->textEdit->append(log);
    //ui->textEdit->append("\n");
    ui->textEdit->ensureCursorVisible();
}
